﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class GongYu : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
     
        if (!IsPostBack)
        {
            if (Request["ID"] != null)
            {
                InitData();
            }
        }
    }

    protected void InitData()
    {

        int id = int.Parse(Request["ID"].ToString());

        try
        {


            DataSet ds = new DataSet();
            ds = new Class1().hsggetdata("select * from 公寓信息 where id=" + id);
            if (ds.Tables[0].Rows.Count > 0)
            {

                this.TextBox1.Text = ds.Tables[0].Rows[0]["楼号"].ToString();
                this.TextBox2.Text = ds.Tables[0].Rows[0]["所在学院"].ToString();
                this.TextBox3.Text = ds.Tables[0].Rows[0]["房间号"].ToString();

                this.DropDownList1.Text = ds.Tables[0].Rows[0]["类型"].ToString();
                this.TextBox4.Text = ds.Tables[0].Rows[0]["可住人数"].ToString();
                this.TextBox5.Text = ds.Tables[0].Rows[0]["已住人数"].ToString();

                this.DropDownList2.Text = ds.Tables[0].Rows[0]["状态"].ToString();
                this.t_startTime.Value = ds.Tables[0].Rows[0]["登记日期"].ToString();

            }


        }
        catch
        {



        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string sql;
        


        if (Request["ID"] != null)
        {
            int id = int.Parse(Request["ID"].ToString());
            sql = "update 公寓信息 set 楼号='" + TextBox1.Text + "',所在学院='" + TextBox2.Text + "',房间号='" + TextBox3.Text + "',类型='" + this.DropDownList1.SelectedItem.Text+ "',可住人数='" + TextBox4.Text + "',已住人数='" + TextBox5.Text + "',状态='" + this.DropDownList2.SelectedItem.Text + "',登记日期='" + this.t_startTime.Value + "' where id=" + id;
            int result;
            result = new Class1().hsgexucute(sql);
            if (result == 1)
            {
                Response.Write("<script>javascript:alert('操作成功');</script>");
            }
            else
            {
                Response.Write("<script>javascript:alert('系统错误，您没有设置好数据库的连接！或您输入了一些非法字符！');</script>");
            }

        }
        else
        {
            sql = "insert into 公寓信息(楼号,所在学院,房间号,类型,可住人数,已住人数,状态,登记日期) values('" + this.TextBox1.Text.Trim() + "','" + this.TextBox2.Text + "','" + this.TextBox3.Text + "','" + this.DropDownList1.SelectedItem.Text + "'," + this.TextBox4.Text + "," + this.TextBox5.Text + ",'" + this.DropDownList2.SelectedItem.Value + "','" + this.t_startTime.Value + "')";

            int result;
            result = new Class1().hsgexucute(sql);
            if (result == 1)
            {
                Response.Write("<script>javascript:alert('添加成功');</script>");
            }
            else
            {
                Response.Write("<script>javascript:alert('系统错误，您没有设置好数据库的连接！');</script>");
            }
        }
    }






    


 
}
